package net.zjitc.servlet;

import javax.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;


/**
 * Created by Administrator on 2017/9/21.
 */
public class AServlet implements Servlet {
//定义成员变量 servletConfig
    private ServletConfig servletConfig=null;
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
 //初始化赋值config
        this.servletConfig=servletConfig;
        System.out.println("born");
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
  //读取servletConfig信息
        String value=this.servletConfig.getInitParameter("Ecoding");
        PrintWriter out=servletResponse.getWriter();
        out.write("<h1>"+value+"</h1>");
        System.out.println("12345");

        ServletContext context=this. servletConfig.getServletContext();
        context.setAttribute("name","Lisa");

    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        System.out.println("die");
    }
}
